package me.vudu.Conflict.Listeners;

import me.vudu.Conflict.ConflictPlugin;

import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.getspout.spoutapi.inventory.SpoutItemStack;
import org.getspout.spoutapi.player.SpoutPlayer;

/**
 * verarbeitet Aktionen auf VuduBrick
 * 
 * @author vwendel
 * 
 */
public class VuduBrickListener implements Listener {

	ConflictPlugin plugin;
	

	public VuduBrickListener(ConflictPlugin plugin) {
		Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
		this.plugin = plugin;
	}

	@EventHandler(priority = EventPriority.HIGH)
	public void CheckVuduBrick(PlayerInteractEvent event) {
		if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
			SpoutPlayer pl = (SpoutPlayer)event.getPlayer();
			SpoutItemStack item = new SpoutItemStack(event.getPlayer().getItemInHand());

			Block b = event.getClickedBlock();

			if (null != b) {
				if (ConflictPlugin.isVuduBrick(b)) {
					if (event.getPlayer().getItemInHand().getTypeId()!=278 && event.getPlayer().getItemInHand().getTypeId()!=285
							&& event.getPlayer().getItemInHand().getTypeId() != ConflictPlugin.VUDUBRICKID) {
						
						if(ConflictPlugin.skillBuildFortify.get(pl.getName()) == 2   //geskillt
								&& item.getTypeId() == 318 && ConflictPlugin.isEnhancedVuduBrick(item.getDurability())) //EVB in Hand
						{
							//nix tun
						}else{
							//event.getPlayer().sendMessage("Du brauchst entweder eine goldene oder eine diamantene Pickaxe um VuduBrick abzubauen!");						
							event.setCancelled(true);
						}
					}
				}
			}
		}

	}
}
